package com.woniu.controller;

import com.woniu.entity.Expense;
import com.woniu.entity.ExpenseDetail;
import com.woniu.entity.UserAppCategory;
import com.woniu.entity.response.ResponseEntity;
import com.woniu.service.IExpenseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hyl
 * @since 2022-08-28
 */
@RestController
@RequestMapping("/brain/expense")
public class ExpenseController {
    @Autowired
    private IExpenseService expenseService;

    //查询报销类别
    @RequestMapping("/list")
    public ResponseEntity findAll() {
        List<Expense> expenses = expenseService.getAll();
        return ResponseEntity.success(expenses,"查询成功");
    }

    @RequestMapping("/listid/{eid}")
    public ResponseEntity findById(@PathVariable("eid") int eid){
        Expense expense = expenseService.getByExpId(eid);
        return  ResponseEntity.success(expense);
    }

    //添加报销类别
    @RequestMapping("/add")
    public ResponseEntity addExpense(@RequestBody Expense expense) {
        expenseService.addExp(expense.getExpCategory());
        return ResponseEntity.success(null);
    }

    //更改报销类别
    @RequestMapping("/update")
    public ResponseEntity updateExpense(@RequestBody Expense expense) {
        expenseService.updateExp(expense);
        return ResponseEntity.success(null);
    }

    @RequestMapping("/test")
    public ResponseEntity test(@RequestBody Expense expense){
        System.out.println(expense);
        return ResponseEntity.success(null,"成功");
    }
}
